<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> 
    <%@include file="/WEB-INF/pages/common/head.jsp"%>
     <%@include file="/resources/datepicker/datepicker.jsp"%> 
    <title><spring:message code="title.ipic.target"/></title>
      <style type="text/css">
        .font_stress{
            color: red;font-size: 13px;font-weight:bold;
        }
    </style>
    <script type="text/javascript">
         var operateDialog;
          var datagrid;
          var lastIndex;
	        $(function() {
	            datagrid=$('#datagrid').datagrid({
	            
			       onClickRow:function(rowIndex){
						datagrid.datagrid('selectRow', rowIndex);
						if (lastIndex != rowIndex){
								datagrid.datagrid('endEdit', lastIndex);
								datagrid.datagrid('beginEdit', rowIndex);
						}else{
							datagrid.datagrid('beginEdit', rowIndex);
						}
						lastIndex = rowIndex;
						setEditing(rowIndex);
					}
	            }); 
	        });
	        
	       function save_(){
	       
	        if($("#supplierCode").val()==''){
               $.messager.alert('提示','供应商不能为空');
                 return;
            }
            if($("#year").val()==''){
            	$.messager.alert('提示','年份不能为空');
                 return;
            }
            
	         var isV =$("#tableForm").form("validate");
            if(!isV) return; 
            var rows = datagrid.datagrid('getRows');
            for ( var i = 0; i < rows.length; i++) {
		        datagrid.datagrid('endEdit', i);
		   	 }
		   	 var updateRows = $('#datagrid').datagrid('getChanges');
             if(updateRows==''){
	              $.messager.alert('<spring:message code='msg.tip'/>',"请填写月份记录后提交数据!");
	               return;
             }
            
            imonJYRH.showZone();
            var effectData = new Object();
            effectData["specialClaimDetail"] = JSON.stringify(rows);
            effectData["specialClaim"] =  JSON.stringify(imonJYRH.serializeObject($("#tableForm *")));
            
            $.ajax({
                url : '${path}/business/supplier_quality/special_claim/ajaxAdd.do',
                 data : effectData,
                 cache : false,
                 async : true,
                 dataType : "json",
                success : function(reMsg) {
                    if(reMsg.success){
                        parent.returnResult();
                        message.show({ msg : reMsg.msg,title : '<spring:message code='msg.tip'/>',showType:'slide'});
                    }else{
                        if(!imonJYRH.isBlank(reMsg.obj)){
                            $.messager.alert('<spring:message code='msg.tip'/>',reMsg['obj']);
                        }else{
                            $.messager.alert('<spring:message code='msg.tip'/>',reMsg['msg']);
                        }
                    }
                    imonJYRH.hideZone();
                }
            });
        }
      function dialogSupplier_(){
            var href = '${path}/basedata/supplier/dialogUI.do';
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.dialog.choose'/>',
                width : 650,
                height : 400
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
     function dialogSupplierReturn(row){
            $("#supplierId").val(row['id']);
            $("#supplierCode").val(row['code']);
            $("#supplierName").val(row['name']);
            operateDialog.dialog('close');
        }
        
     function setEditing(rowIndex){
		var rows = datagrid.datagrid('getRows');
	    var editors = datagrid.datagrid('getEditors', rowIndex);
	    
	    var incident1 = rows[rowIndex]['incident1']; 
	    var incident2 = rows[rowIndex]['incident2']; 
	    var incident3 = rows[rowIndex]['incident3']; 
	    var incident4 = rows[rowIndex]['incident4']; 
	    
	    var i1 = editors[0];   
	    var i2 = editors[1];
	    var i3 = editors[2];
	    var i4 = editors[3];
	    var value1=0;
	    var value2=0;
	    var value3=0;
	    var value4=0;
	    
	    i1.target.bind('change', function(){
	       value1=i1.target.val(); 
	      var total=0;
	      
	      if(!imonJYRH.isBlank(i1.target.val())){
	        total=total+i1.target.val()*(-2);
	       }
	       
	       if(value2!=0){
	            total=total+value2*(-5);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident2)){
			        total=total+rows[rowIndex].incident2*(-5);
			    }
	       } 
	       
	      
	       if(value3!=0){
	            total=total+value3*(-7);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident3)){
			        total=total+rows[rowIndex].incident3*(-7);
			    }
	       } 
	       
	        if(value4!=0){
	            total=total+value4*(-10);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident4)){
			        total=total+rows[rowIndex].incident4*(-10);
			    }
	       } 
	       
	        rows[rowIndex].value=total;
	    });   
	    i2.target.bind('change', function(){
	   		value2=i2.target.val();
	         var total=0;
			      
		   if(!imonJYRH.isBlank(i2.target.val())){
	          total=total+i2.target.val()*(-5);
	       }
	       
	       if(value1!=0){
	            total=total+value1*(-2);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident1)){
			        total=total+rows[rowIndex].incident1*(-2);
			    }
	       } 
	       
	      
	       if(value3!=0){
	            total=total+value3*(-7);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident3)){
			        total=total+rows[rowIndex].incident3*(-7);
			    }
	       } 
	       
	        if(value4!=0){
	            total=total+value4*(-10);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident4)){
			        total=total+rows[rowIndex].incident4*(-10);
			    }
	       } 
		     
		     
		     rows[rowIndex].value=total;
	    });
		    i3.target.bind('change', function(){   
		    value3=i3.target.val();
	         var total=0;
			    
		   if(!imonJYRH.isBlank(i3.target.val())){
	          total=total+i3.target.val()*(-7);
	       }
	       
	       if(value1!=0){
	            total=total+value1*(-2);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident1)){
			        total=total+rows[rowIndex].incident1*(-2);
			    }
	       } 
	       
	      
	       if(value2!=0){
	            total=total+value2*(-5);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident2)){
			        total=total+rows[rowIndex].incident2*(-5);
			    }
	       } 
	       
	        if(value4!=0){
	            total=total+value4*(-10);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident4)){
			        total=total+rows[rowIndex].incident4*(-10);
			    }
	       }    
			    
			    
		    rows[rowIndex].value=total;
	    });
	    i4.target.bind('change', function(){
	       value4=i4.target.val();
	        var total=0;
			
			if(!imonJYRH.isBlank(i4.target.val())){
	          total=total+i4.target.val()*(-10);
	       }
	       
	       if(value1!=0){
	            total=total+value1*(-2);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident1)){
			        total=total+rows[rowIndex].incident1*(-2);
			    }
	       } 
	       
	      
	       if(value2!=0){
	            total=total+value2*(-5);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident2)){
			        total=total+rows[rowIndex].incident2*(-5);
			    }
	       } 
	       
	        if(value3!=0){
	            total=total+value3*(-7);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident3)){
			        total=total+rows[rowIndex].incident3*(-7);
			    }
	       }  
			     
		    rows[rowIndex].value=total;
	    });
	} 
        
    </script>
</head>
<body class="easyui-layout">
   <div data-options="region:'center'">
    <div class="datagrid-toolbar" style="height:410px">
        <table width="100%"  class="tableForm" id="tableForm">
            <tr>
                <td>
                    <span style="color:red;">*</span>供应商：
                         <input type="hidden" id='supplierId' name="supplierId"/>
                        <input type="text" id="supplierCode" onclick="dialogSupplier_();" readonly="true"/>
                </td>
                <td>
                    SupplierName供应商名称：<input type="text" id="supplierName" style="width: 180px;" disabled/>
                </td>
                <td>
                    <span style="color:red;">*</span>年份：&nbsp;&nbsp;&nbsp;&nbsp;  <input type="text" name="year" value="${year}" id="year"
                               onFocus="WdatePicker({isShowClear:false,isShowToday:false,dateFmt:'yyyy',readOnly:true})" class="field Wdate"/>
                </td>
            </tr>
        </table>
        <hr width="650px"/>
        <table width="100%" id="datagrid" singleSelect="true" class="tableForm" remoteSort="false">
            <thead>
            <tr>
            	<th field="month" width="60" hidden="true">月份</th>
                <th field="month1" width="60">月份</th>
                <th field="incident1" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i1</th>
                <th field="incident2" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i2</th>
                <th field="incident3" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i3</th>
                <th field="incident4" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i4</th>
                <th field="value" width="100" >得分</th>
                <th field="comment" width="250" data-options="editor:{type:'text'}">评论</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td field="month" width="60" hidden="true">01</td>
                <td>一月</td>
                <td field="spe1i1"></td>
                <td field="spe1i2"></td>
                <td field="spe1i3"></td>
                <td field="spe1i4"></td>
                <td field="value1"></td>
                <td field="comment1"></td>
            </tr>
            <tr>
            	<td field="month" width="60" hidden="true">02</td>
                <td>二月</td>
                <td field="spe2i1"></td>
                <td field="spe2i2"></td>
                <td field="spe2i3"></td>
                <td field="spe2i4"></td>
                <td field="value2"></td>
                <td field="comment2"></td>
            </tr>
            <tr>
                <td field="month" width="60" hidden="true">03</td>
                <td>三月</td>
                <td field="spe3i1"></td>
                <td field="spe3i2"></td>
                <td field="spe3i3"></td>
                <td field="spe3i4"></td>
                <td field="value3"></td>
                <td field="comment3"></td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">04</td>
                <td>四月</td>
                <td field="spe4i1"></td>
                <td field="spe4i2"></td>
                <td field="spe4i3"></td>
                <td field="spe4i4"></td>
                <td field="value4"></td>
                <td field="comment4"></td>
            </tr>
            <tr>
                 <td field="month" width="60" hidden="true">05</td>
                <td>五月</td>
                <td field="spe5i1"></td>
                <td field="spe5i2"></td>
                <td field="spe5i3"></td>
                <td field="spe5i4"></td>
                <td field="value5"></td>
                <td field="comment5"></td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">06</td>
                <td>六月</td>
               <td field="spe6i1"></td>
                <td field="spe6i2"></td>
                <td field="spe6i3"></td>
                <td field="spe6i4"></td>
                <td field="value6"></td>
                <td field="comment6"></td>
            </tr>
            <tr>
                <td field="month" width="60" hidden="true">07</td>
                <td>七月</td>
                <td field="spe7i1"></td>
                <td field="spe7i2"></td>
                <td field="spe7i3"></td>
                <td field="spe7i4"></td>
                <td field="value7"></td>
                <td field="comment7"></td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">08</td>
                <td>八月</td>
               <td field="spe1i1"></td>
                <td field="spe1i2"></td>
                <td field="spe1i3"></td>
                <td field="spe1i4"></td>
                <td field="value8"></td>
                <td field="comment8"></td>
            </tr>
             <tr>
               <td field="month" width="60" hidden="true">09</td>
               <td>九月</td>
               <td field="spe9i1"></td>
                <td field="spe9i2"></td>
                <td field="spe9i3"></td>
                <td field="spe9i4"></td>
                <td field="value9"></td>
                <td field="comment9"></td>
            </tr>
            <tr>
                <td field="month" width="60" hidden="true">10</td>
                <td>十月</td>
               <td field="spe10i1"></td>
                <td field="spe10i2"></td>
                <td field="spe10i3"></td>
                <td field="spe10i4"></td>
                <td field="value10"></td>
                <td field="comment10"></td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">11</td>
                <td>十一月</td>
                <td field="spe11i1"></td>
                <td field="spe11i2"></td>
                <td field="spe11i3"></td>
                <td field="spe11i4"></td>
                <td field="value11"></td>
                <td field="comment11"></td>
            </tr>
            <tr>
           		<td field="month" width="60" hidden="true">12</td>
                <td>十二月</td>
                <td field="spe12i1"></td>
                <td field="spe12i2"></td>
                <td field="spe12i3"></td>
                <td field="spe12i4"></td>
                <td field="value12"></td>
                <td field="comment12"></td>
            </tr>
            </tbody>
        </table>
        <br />
        <div align="right">
            <a class="easyui-linkbutton" href="javascript:void(0);" iconCls="icon-save" onclick="save_();"><spring:message code='button.save'/></a>
            <a class="easyui-linkbutton" href="javascript:void(0);" iconCls="icon-no" onclick="parent.operateDialog.dialog('close');"><spring:message code='button.close'/></a>
        </div>
    </div>
</div>
<div id="operateDialog" class="easyui-dialog"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
    <iframe scrolling="auto" id='operateIFrame' frameborder="0"  src="" style="width:100%;height:100%;"/>
</div>
</body>
</html>